<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Timu extends User_Controller {

	function __construct(){
		parent::__construct();
	}

	//课本列表
	function index($subject_id = 33, $limit = 0){
		$this->load->model("Tk_test_topic_historys");
		$this->load->model("Books");
		$conditions['subject_id'] = $subject_id;
		$subject_data = $this->Books->get_books($limit, $this->offset = 100, $conditions);
		
		$this->smarty->assign("menu", 'tiku');
		$this->smarty->assign("subject_list", $subject_data['result']);
		$this->smarty->display("timu/index.html");
	}

	//章节列表
	function chapter_list($book_id = 0, $limit = 0){
		$book_info = get_field_by_where("b_book", "*", "id='{$book_id}'");
		if(!$book_info){
			show_message($_SERVER['HTTP_REFERER'], "课本不存在");exit;
		}
		$this->load->model("Books");
		$conditions['book_id'] = $book_id;
		$chapter_list = $this->Books->get_book_chapter_list($limit, $this->offset, $conditions);
		$this->smarty->assign("chapter_list", $chapter_list);
		$this->smarty->assign("book_info", $book_info);
		$this->smarty->assign("book_id", $book_id);
		$this->smarty->display("timu/chapter_list.html");
	}

	//章节练习
	function start_practice($chapter_id = 0, $timu_id = 0, $limit = 0){
		$chapter_id = intval($chapter_id);
		$chapter_info = get_field_by_where("b_book_chapter", "*", "id=$chapter_id");
		// print_r($chapter_info);
		$this->load->model("Timus");
		$conditions['chapter_id'] = $chapter_id;
		$conditions['timu_id'] = $timu_id;
		$topic_list = $this->Timus->get_timu(0, $this->offset = 3, $conditions);
		if(!empty($topic_list['count'])){
			foreach ($topic_list['result'] as $key => $value) {
				$topic_list['result'][$key]['children'] = $this->Timus->get_timu_children($value['id']);
			}
		}
		print_r($topic_list);exit;
		if(isset($topic_list['count']) && $topic_list['count'] > 0){
			foreach ($topic_list['result'] as $key => $value) {
				//查询答案
				$nothing_answer = array(4, 8, 9, 10);	//不需要答案的题目类型
				if(in_array($value['type'], $nothing_answer)) break;
				if($value['type'] == 7){
					$timu_result = $this->Timus->get_timu_calc_result($value['timu_children_id']);
				}else{
					$timu_result = $this->Timus->get_timu_reuslt($value['timu_children_id']);
				}
				$topic_list['result'][$key]['result'] = $timu_result;
				/*if($value['type'] == 1 ||$value['type'] == 2 || $value['type'] == 3){
					$topic_result = $this->Topics->get_timu_reuslt($value['id']);
					if($topic_result){
						$value['result'] = $topic_result;
					}
				}elseif($value['type'] == 6){
					$calc = $this->Topics->get_timu_calc_result($value['id']);
					if($calc){
						$value['calc'] = '';
						foreach ($calc as $k => $f) {
							# code...
							if($f['type'] == 1){
								$value['calc'] .= $f['value'] . " ";
							}else{
								$value['calc'] .= $fh[$f['value']] . " ";
							}
						}
					}
				}
				$volume_info['topic_list'][$value['type']][] = $value;*/
			}
		}
		print_r($topic_list);
	}
}